(function(){"use strict";var e=BX.namespace("BX.UI");if(e.Switcher){return}var t=[];function i(e){this.init(e);t.push(this)}i.getById=function(e){return t.filter(function(t){return t.id===e})[0]||null};i.getList=function(){return t};i.className="ui-switcher";i.initByClassName=function(){var e=document.getElementsByClassName(i.className);e=BX.convert.nodeListToArray(e);e.forEach(function(e){if(e.getAttribute("data-switcher-init")){return}new i({node:e})})};i.prototype={events:{toggled:"toggled",checked:"checked",unchecked:"unchecked"},handlers:{},attributeName:"data-switcher",attributeInitName:"data-switcher-init",classNameOff:"ui-switcher-off",classNameSize:{small:"ui-switcher-size-sm"},classNameColor:{green:"ui-switcher-color-green"},popup:null,content:null,popupParameters:null,loading:false,init:function(e){e=e||{};if(e.attributeName){this.attributeName=e.attributeName}if(e.handlers){this.handlers=e.handlers}if(e.node){if(!BX.type.isDomNode(e.node)){throw new Error("Parameter `node` DOM Node expected.")}this.node=e.node;var t=this.node.getAttribute(this.attributeName);try{t=JSON.parse(t)||{}}catch(e){t={}}if(t.id){this.id=t.id}this.checked=!!t.checked;this.inputName=t.inputName;if(typeof t.color!=="undefined"){e.color=t.color}if(typeof t.size!=="undefined"){e.size=t.size}}else{this.node=document.createElement("span")}if(e.id){this.id=e.id}if(!this.id){this.id=Math.random()}if(typeof e.checked==="boolean"){this.checked=e.checked}if(e.inputName){this.inputName=e.inputName}if(this.classNameSize[e.size]){this.node.classList.add(this.classNameSize[e.size])}if(this.classNameColor[e.color]){this.node.classList.add(this.classNameColor[e.color])}this.initNode();this.check(this.checked,false)},renderTo:function(e){return e.appendChild(this.getNode())},getNode:function(){return this.node},initNode:function(){var e=this.node;if(e.getAttribute(this.attributeInitName)){return}e.setAttribute(this.attributeInitName,"y");BX.addClass(e,i.className);e.innerHTML='<span class="ui-switcher-cursor"></span>\n'+'<span class="ui-switcher-enabled">'+BX.message("UI_SWITCHER_ON")+"</span>\n"+'<span class="ui-switcher-disabled">'+BX.message("UI_SWITCHER_OFF")+"</span>\n";if(this.inputName){this.inputNode=document.createElement("input");this.inputNode.type="hidden";this.inputNode.name=this.inputName;this.node.appendChild(this.inputNode)}BX.bind(e,"click",this.toggle.bind(this))},toggle:function(){this.check(!this.isChecked())},isChecked:function(){return this.checked},fireEvent:function(e){BX.onCustomEvent(this,e);if(this.handlers[e]){this.handlers[e].call(this)}},check:function(e,t){if(this.loading){return}this.checked=e;if(this.inputNode){this.inputNode.value=this.checked?"Y":"N"}t=t!==false;if(this.checked){BX.removeClass(this.node,this.classNameOff);t?this.fireEvent(this.events.unchecked):null}else{BX.addClass(this.node,this.classNameOff);t?this.fireEvent(this.events.checked):null}BX.onCustomEvent(this,this.events.toggled);t?this.fireEvent(this.events.toggled):null},setLoading:function(e){this.loading=!!e;var t=this.getNode().querySelector(".ui-switcher-cursor");if(this.loading){t.innerHTML='<svg viewBox="25 25 50 50">'+'<circle class="ui-sidepanel-wrapper-loader-path" cx="50" cy="50" r="19" fill="none" stroke-width="5" stroke-miterlimit="10"></circle>'+"</svg>"}else{t.innerHTML=""}},isLoading:function(){return this.loading}};e.Switcher=i;e.Switcher.initByClassName();BX.ready(function(){e.Switcher.initByClassName()})})();
//# sourceMappingURL=ui.switcher.map.js